package com.cetc39.action;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import com.cetc39.util.FilePathUtil;
import com.opensymphony.xwork2.ActionSupport;

public class DownloadAction extends ActionSupport {
	private InputStream fileInputStream;
	private String filePath;
	private String filename;

	public InputStream getFileInputStream() {
		return fileInputStream;
	}
	
	@Override
	public String execute() throws Exception {
		String[] fileNameString = FilePathUtil.getHttpURLPath(filePath).split("/");
		filename = fileNameString[fileNameString.length - 1];
		filename = new String(filename.getBytes(), "ISO8859-1");
		File f = new File(filePath);
		fileInputStream = new FileInputStream(f);
		return super.execute();
	}

	public String getFilePath() {
		return filePath;
	}

	public void setFilePath(String filePath) {
		this.filePath = filePath;
	}

	public String getFilename() {
		return filename;
	}

	



	
}
